package com.kgc.ssm.controller;

import com.kgc.ssm.entity.Stock;
import com.kgc.ssm.entity.SysUsers;
import com.kgc.ssm.entity.dto.Result;
import com.kgc.ssm.service.StockService;
import com.kgc.ssm.service.SysUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 待审批采购计划处理controller
 */

@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private StockService stockService;

    @Autowired
    private SysUsersService sysUsersService;

    @GetMapping("/page")
    public Result<List<Stock>> findPage(Integer pageNum, Integer pageSize) {
        return stockService.findPage(pageNum, pageSize);
    }

    @GetMapping("/getbyid")
    public Result<Object> getById(Integer id) {
        List<Map<String, Object>> list = stockService.findById(id);
        return new Result<>("查询成功", 200, list);
    }

    @PostMapping("/updateByPrimaryKeySelective")
    public Result<Object> updateByPrimaryKeySelective(@RequestBody Stock row) {
        SysUsers sysUsers = sysUsersService.findByLoginId(row.getLeader());
        if (sysUsers != null) {
            row.setLeaderId(sysUsers.getId() + "");
        }
        stockService.updateByPrimaryKeySelective(row);
        return new Result<>("查询成功", 200, null);
    }
}
